From 6029c82678ad50616b288848355c8d26391494ea Mon Sep 17 00:00:00 2001 From: robertlipe Date: Mon, 11 Feb 2013 21:50:47 +0000 Subject: [PATCH] Tested: Move icon_descr to a reference-counted QString, freeing us from the horror of the 'is_dynamic? xfree()' mess and the issues in waypt_dupe. The code is better in some ways, but suffers now while there are still a lot of const char*/QString edges, but there's only so much you can do in one commit and still keep the tree running. Builds Mac and Mingw-cross. valgrind runs on Ubuntu. (and caught a few errors as I introduced them.) --- gpsbabel/an1.cc | 11 +++++++---- gpsbabel/avltree.cc | 10 ++++++++++ gpsbabel/avltree.h | 1 + gpsbabel/bcr.cc | 6 +++--- gpsbabel/bushnell.cc | 12 ++++++++---- gpsbabel/cetus.cc | 6 +++--- gpsbabel/compegps.cc | 11 ++--------- gpsbabel/coto.cc | 11 ++++------- gpsbabel/csv_util.cc | 5 ++--- gpsbabel/defs.h | 5 +---- gpsbabel/delbin.cc | 16 ++++++++-------- gpsbabel/easygps.cc | 3 +-- gpsbabel/g7towin.cc | 2 -- gpsbabel/garmin.cc | 9 ++++----- gpsbabel/garmin_tables.cc | 40 +++++++++++++++++++-------------------- gpsbabel/garmin_tables.h | 6 +++--- gpsbabel/garmin_txt.cc | 3 +-- gpsbabel/gbfile.cc | 9 +++++++++ gpsbabel/gbfile.h | 1 + gpsbabel/gdb.cc | 7 +++---- gpsbabel/geo.cc | 3 +-- gpsbabel/geoniche.cc | 33 ++++++++++++++------------------ gpsbabel/gpilots.cc | 1 - gpsbabel/gpsutil.cc | 4 ++-- gpsbabel/gpx.cc | 3 +-- gpsbabel/gtm.cc | 12 +++++------- gpsbabel/gtrnctr.cc | 3 +-- gpsbabel/hiketech.cc | 3 +-- gpsbabel/humminbird.cc | 6 +++--- gpsbabel/kml.cc | 9 ++++----- gpsbabel/lowranceusr.cc | 17 ++++++++--------- gpsbabel/magellan.h | 4 ++-- gpsbabel/magproto.cc | 16 ++++++++-------- gpsbabel/mapsend.cc | 29 ++++++++++++++-------------- gpsbabel/mapsource.cc | 10 ++++------ gpsbabel/mmo.cc | 14 ++++++-------- gpsbabel/navilink.cc | 6 +++--- gpsbabel/osm.cc | 5 ++--- gpsbabel/ozi.cc | 7 +++---- gpsbabel/pathaway.cc | 5 ++--- gpsbabel/psitrex.cc | 2 +- gpsbabel/raymarine.cc | 8 ++++---- gpsbabel/tiger.cc | 8 ++++---- gpsbabel/unicsv.cc | 15 +++++++++++---- gpsbabel/waypt.cc | 8 ++------ gpsbabel/wfff_xml.cc | 9 ++++----- gpsbabel/xol.cc | 5 ++--- 47 files changed, 203 insertions(+), 216 deletions(-) diff --git a/gpsbabel/an1.cc b/gpsbabel/an1.cc index a2263bacb..64b7adf6d 100644 --- a/gpsbabel/an1.cc +++ b/gpsbabel/an1.cc @@ -801,14 +801,17 @@ Write_One_AN1_Waypoint(const waypoint* wpt) rec->serial = serial++; if (rec->type == 0x12) { /* image */ - if (strstr(wpt->icon_descr, ":\\")) { - rec->image_name = xstrdup(wpt->icon_descr); + if (wpt->icon_descr.contains(":\\")) { + rec->image_name = xstrdup(wpt->icon_descr.toUtf8().data()); rec->height = -244; rec->width = -1; } } - if (!rec->image_name && wpt->icon_descr) { - FindIconByName((char*)(void*)wpt->icon_descr, &rec->guid); + if (!rec->image_name && !wpt->icon_descr.isNull()) { +// FIXME: WTH? +char* t = xstrdup(wpt->icon_descr.toUtf8().data()); + FindIconByName(t, &rec->guid); +xfree(t); } Write_AN1_Waypoint(outfile, rec); diff --git a/gpsbabel/avltree.cc b/gpsbabel/avltree.cc index caccace9c..1d7cdb29a 100644 --- a/gpsbabel/avltree.cc +++ b/gpsbabel/avltree.cc @@ -193,6 +193,16 @@ avltree_find(const avltree_t* tree, const char* key, const void** data) return (node) ? 1 : 0; } +int +avltree_find(const avltree_t* tree, const QString key, const void** data) +{ + const char*t = xstrdup(key.toUtf8().data()); + int r = avltree_find(tree, key, data); + xfree(t); + return r; + +} + /* Get the first (the MIN-) entry of the tree */ diff --git a/gpsbabel/avltree.h b/gpsbabel/avltree.h index c08c3a8b3..5feea19dd 100644 --- a/gpsbabel/avltree.h +++ b/gpsbabel/avltree.h @@ -79,6 +79,7 @@ avltree_t* avltree_dupe(const avltree_t* tree, const char* module); /* Find key [key] in tree */ int avltree_find(const avltree_t* tree, const char* key, const void** data); +int avltree_find(const avltree_t* tree, const QString key, const void** data); /* Get the first (the MIN-) entry of the tree */ const char* avltree_first(const avltree_t* tree, const void** data); diff --git a/gpsbabel/bcr.cc b/gpsbabel/bcr.cc index 5561e379a..60358a597 100644 --- a/gpsbabel/bcr.cc +++ b/gpsbabel/bcr.cc @@ -154,18 +154,18 @@ bcr_handle_icon_str(const char* str, waypoint* wpt) } static const char* -get_bcr_icon_from_icon_descr(const char* icon_descr) +get_bcr_icon_from_icon_descr(QString icon_descr) { const char* result = BCR_DEF_ICON; - if (icon_descr) { + if (!icon_descr.isNull()) { bcr_icon_mapping_t* m; for (m = bcr_icon_mapping; (m->bcr_name); m++) { if (! m->mps_name) { continue; } - if (case_ignore_strcmp(icon_descr, m->mps_name) == 0) { + if (icon_descr.compare(m->mps_name, Qt::CaseInsensitive) == 0) { result = m->bcr_name; break; } diff --git a/gpsbabel/bushnell.cc b/gpsbabel/bushnell.cc index 029cbca59..d97bb7f81 100644 --- a/gpsbabel/bushnell.cc +++ b/gpsbabel/bushnell.cc @@ -126,11 +126,16 @@ icon_mapping_t bushnell_icons[] = { }; static unsigned int -bushnell_get_icon_from_name(const char* name) +bushnell_get_icon_from_name(QString name) { icon_mapping_t* t; + + if (name.isNull()) { + name = "Waypoint"; + } + for (t = bushnell_icons; t->icon > 0; t++) { - if (0 == case_ignore_strcmp(name, t->icon)) { + if (0 == name.compare(t->icon, Qt::CaseInsensitive)) { return t->symbol; } } @@ -232,8 +237,7 @@ bushnell_write_one(const waypoint* wpt) file_out = gbfopen_le(fname, "wb", MYNAME); gbfputint32(wpt->latitude * 10000000, file_out); gbfputint32(wpt->longitude * 10000000, file_out); - gbfputc(bushnell_get_icon_from_name(wpt->icon_descr ? wpt->icon_descr : - "Waypoint"), file_out); + gbfputc(bushnell_get_icon_from_name(wpt->icon_descr), file_out); gbfputc(0x01, file_out); // Proximity alarm. 1 == "off", 3 == armed. ident = mkshort(mkshort_handle, wpt->shortname); diff --git a/gpsbabel/cetus.cc b/gpsbabel/cetus.cc index beca8cd30..8f29e2fbf 100644 --- a/gpsbabel/cetus.cc +++ b/gpsbabel/cetus.cc @@ -565,12 +565,12 @@ cetus_writewpt(const waypoint* wpt) xfree(desc_short); xfree(desc_long); - if (appendicon && wpt->icon_descr) { + if (appendicon && !wpt->icon_descr.isNull()) { int left = DESCSZ - strlen(vdata); - int ilen = strlen(wpt->icon_descr); + int ilen = strlen(wpt->icon_descr.toUtf8().data()); if (ilen && left > (ilen+3)) { strcat(vdata, " ("); - strcat(vdata, wpt->icon_descr); + strcat(vdata, wpt->icon_descr.toUtf8().data()); strcat(vdata, ")"); } } diff --git a/gpsbabel/compegps.cc b/gpsbabel/compegps.cc index 66a29e592..093b818da 100644 --- a/gpsbabel/compegps.cc +++ b/gpsbabel/compegps.cc @@ -243,8 +243,7 @@ parse_wpt_info(const char* buff, waypoint* wpt) /* "w" */ #endif switch (col) { case 0: - wpt->icon_descr = xstrdup(c); - wpt->wpt_flags.icon_descr_is_dynamic = 1; + wpt->icon_descr = c; break; case 1: break; /* Text postion */ @@ -502,14 +501,8 @@ write_waypt_cb(const waypoint* wpt) if ((wpt->icon_descr != NULL) || (wpt->wpt_flags.proximity) || \ (option_icon != NULL)) { - char* icon = option_icon; - - if (wpt->icon_descr != NULL) { - icon = (char*) wpt->icon_descr; - } - gbfprintf(fout, "w %s,0,0.0,16777215,255,1,7,,%.1f\n", - (icon != NULL) ? icon : "Waypoint", + wpt->icon_descr.isNull() ? "Waypoint" : wpt->icon_descr.toUtf8().data(), WAYPT_GET(wpt, proximity, 0)); } xfree(name); diff --git a/gpsbabel/coto.cc b/gpsbabel/coto.cc index a08d7b74d..adf5775f5 100644 --- a/gpsbabel/coto.cc +++ b/gpsbabel/coto.cc @@ -271,9 +271,6 @@ coto_wpt_read(void) wpt_tmp->shortname = xstrndup(rec->name, sizeof(rec->name)); wpt_tmp->icon_descr = coto_get_icon_descr(pdb_rec->category, app); - if (wpt_tmp->icon_descr) { - wpt_tmp->wpt_flags.icon_descr_is_dynamic = 1; - } if ((c = strstr(rec->notes, "\nNotes:\n"))) { /* remove our contruct */ wpt_tmp->notes = xstrdup(c + 8); @@ -382,9 +379,9 @@ coto_wpt_write(const waypoint* wpt) xfree(notes); } - if (wpt->icon_descr) { + if (!wpt->icon_descr.isNull()) { for (i = 1; i < 16; i++) - if (!strncmp(wpt->icon_descr, ai->categories[i], 16)) { + if (!strncmp(wpt->icon_descr.toUtf8().data(), ai->categories[i], 16)) { cat=i; break; } @@ -392,11 +389,11 @@ coto_wpt_write(const waypoint* wpt) // We have a new one if (ai->maxid<15) { i = ++ai->maxid; - snprintf(ai->categories[i], 16, "%s", wpt->icon_descr); + snprintf(ai->categories[i], 16, "%s", wpt->icon_descr.toUtf8().data()); cat = ai->ids[i] = i; } else { // We're full! - warning(MYNAME ": Categories full. Category '%s' written as %s.\n", wpt->icon_descr, zerocat?zerocat:"Not Assigned"); + warning(MYNAME ": Categories full. Category '%s' written as %s.\n", wpt->icon_descr.toUtf8().data(), zerocat?zerocat:"Not Assigned"); } } } diff --git a/gpsbabel/csv_util.cc b/gpsbabel/csv_util.cc index 3cefc34cb..f7c9616a5 100644 --- a/gpsbabel/csv_util.cc +++ b/gpsbabel/csv_util.cc @@ -1041,7 +1041,6 @@ xcsv_parse_val(const char* s, waypoint* wpt, const field_map_t* fmp, break; case XT_ICON_DESCR: wpt->icon_descr = csv_stringtrim(s, "", 0); - wpt->wpt_flags.icon_descr_is_dynamic = 1; break; /* LATITUDE CONVERSIONS**************************************************/ @@ -1724,8 +1723,8 @@ xcsv_waypt_pr(const waypoint* wpt) break; case XT_ICON_DESCR: writebuff(buff, fmp->printfc, - (wpt->icon_descr && *wpt->icon_descr) ? - wpt->icon_descr : fmp->val); + (!wpt->icon_descr.isNull()) ? + wpt->icon_descr.toUtf8().data() : fmp->val); break; /* LATITUDE CONVERSION***********************************************/ diff --git a/gpsbabel/defs.h b/gpsbabel/defs.h index 9447a56b2..c72882830 100644 --- a/gpsbabel/defs.h +++ b/gpsbabel/defs.h @@ -386,7 +386,6 @@ class url_link { class wp_flags { public: wp_flags() : - icon_descr_is_dynamic(0), shortname_is_synthetic(0), cet_converted(0), fmt_use(0), @@ -397,7 +396,6 @@ class wp_flags { depth(0), is_split(0), new_trkseg(0) {} - unsigned int icon_descr_is_dynamic:1; unsigned int shortname_is_synthetic:1; unsigned int cet_converted:1; /* strings are converted to UTF8; interesting only for input */ unsigned int fmt_use:1; /* lightweight "extra data" */ @@ -465,7 +463,6 @@ public: url_next(NULL), url(NULL), url_link_text(NULL), - icon_descr(NULL), #if NEWTIME // creation_time(QDateTime::fromTime_t(0)), #else @@ -546,7 +543,7 @@ public: char* url_link_text; wp_flags wpt_flags; - const char* icon_descr; + QString icon_descr; #if NEWTIME gpsbabel::DateTime creation_time; #else diff --git a/gpsbabel/delbin.cc b/gpsbabel/delbin.cc index 1a24d961f..41d2b9355 100644 --- a/gpsbabel/delbin.cc +++ b/gpsbabel/delbin.cc @@ -1006,9 +1006,9 @@ decode_waypoint(const void* data) wp->altitude = f; } wp->icon_descr = waypoint_symbol(p->symbol); - if (wp->icon_descr) { - wp->icon_descr = xstrdup(wp->icon_descr); - } +// if (!wp->icon_descr.isNull()) { +// wp->icon_descr = wp->icon_descr; +// } if (p->name_size && p->name[0]) { wp->description = xstrdup(p->name); } @@ -1186,7 +1186,7 @@ get_gc_notes(const waypoint* wp, int* symbol, char** notes, unsigned* notes_size case gt_ape: break; } - if (0 == strcmp(wp->icon_descr, "Geocache Found")) { + if (0 == (wp->icon_descr.compare("Geocache Found"))) { gc_sym = 124; } if (wp->description) { @@ -1201,8 +1201,8 @@ get_gc_notes(const waypoint* wp, int* symbol, char** notes, unsigned* notes_size if (gc_sym && opt_gcsym && atoi(opt_gcsym)) { gbfprintf(fd, "%s\n", waypoint_symbol(gc_sym)); *symbol = gc_sym; - } else if (wp->icon_descr) { - gbfprintf(fd, "%s\n", wp->icon_descr); + } else if (!wp->icon_descr.isNull()) { + gbfprintf(fd, "%s\n", wp->icon_descr.toUtf8().data()); } switch (wp->gc_data->container) { case gc_micro: @@ -1423,8 +1423,8 @@ write_waypoint(const waypoint* wp) le_write_float(p->elevation, elev); if (symbol < 0) { symbol = 0; - if (wp->icon_descr) { - symbol = waypoint_symbol_index(wp->icon_descr); + if (!wp->icon_descr.isNull()) { + symbol = waypoint_symbol_index(wp->icon_descr.toUtf8().data()); } } p->symbol = symbol; diff --git a/gpsbabel/easygps.cc b/gpsbabel/easygps.cc index 11c771cd7..f644ccd20 100644 --- a/gpsbabel/easygps.cc +++ b/gpsbabel/easygps.cc @@ -102,7 +102,6 @@ data_read(void) break; case 7: wpt_tmp->icon_descr = gbfgetpstr(file_in);; - wpt_tmp->wpt_flags.icon_descr_is_dynamic = 1; break; case 8: /* NULL Terminated (vs. pascal) descr */ wpt_tmp->notes = gbfgetcstr(file_in); @@ -154,7 +153,7 @@ ez_disp(const waypoint* wpt) gbfputc(3, file_out); gbfputpstr(wpt->description, file_out); } - if (wpt->icon_descr) { + if (!wpt->icon_descr.isNull()) { gbfputc(7, file_out); gbfputpstr(wpt->icon_descr, file_out); } diff --git a/gpsbabel/g7towin.cc b/gpsbabel/g7towin.cc index 6a31212a5..b910d6146 100644 --- a/gpsbabel/g7towin.cc +++ b/gpsbabel/g7towin.cc @@ -115,7 +115,6 @@ parse_line(char* buff, int index, const char* delimiter, waypoint* wpt) case WAYPT__OFS + 2: wpt->icon_descr = gt_find_desc_from_icon_number( atoi(cin), PCX, &dyn); - wpt->wpt_flags.icon_descr_is_dynamic = dyn; break; case WAYPT__OFS + 4: @@ -474,7 +473,6 @@ data_read(void) cdata++; wpt->icon_descr = gt_find_desc_from_icon_number( atoi(cdata), PCX, &dyn); - wpt->wpt_flags.icon_descr_is_dynamic = dyn; } waypt_add(wpt); break; diff --git a/gpsbabel/garmin.cc b/gpsbabel/garmin.cc index 1f0d2243c..51cf03c34 100644 --- a/gpsbabel/garmin.cc +++ b/gpsbabel/garmin.cc @@ -97,7 +97,7 @@ arglist_t garmin_args[] = { }; static const char* d103_symbol_from_icon_number(unsigned int n); -static int d103_icon_number_from_symbol(const char* s); +static int d103_icon_number_from_symbol(QString s); static void @@ -369,7 +369,6 @@ waypt_read(void) int dyn = 0; wpt_tmp->icon_descr = gt_find_desc_from_icon_number( way[i]->smbl, PCX, &dyn); - wpt_tmp->wpt_flags.icon_descr_is_dynamic = dyn; } /* * If a unit doesn't store altitude info (i.e. a D103) @@ -1273,16 +1272,16 @@ d103_symbol_from_icon_number(unsigned int n) } static int -d103_icon_number_from_symbol(const char* s) +d103_icon_number_from_symbol(QString s) { unsigned int i; - if (NULL == s) { + if (s.isNull()) { return 0; } for (i = 0; i < sizeof(d103_icons) / sizeof(d103_icons[0]); i++) { - if (0 == case_ignore_strcmp(s, d103_icons[i])) { + if (0 == (s.compare(d103_icons[i]), Qt::CaseInsensitive)) { return i; } } diff --git a/gpsbabel/garmin_tables.cc b/gpsbabel/garmin_tables.cc index 49ceea926..2af5b7063 100644 --- a/gpsbabel/garmin_tables.cc +++ b/gpsbabel/garmin_tables.cc @@ -756,13 +756,13 @@ gt_find_desc_from_icon_number(const int icon, garmin_formats_e garmin_format, in case MAPSOURCE: case GDB: if (icon == i->mpssymnum) { - return (char*)i->icon; + return i->icon; } break; case PCX: case GARMIN_SERIAL: if (icon == i->pcxsymnum) { - return (char*)i->icon; + return i->icon; } break; default: @@ -772,14 +772,14 @@ gt_find_desc_from_icon_number(const int icon, garmin_formats_e garmin_format, in return DEFAULT_ICON_DESCR; } -int gt_find_icon_number_from_desc(const char* desc, garmin_formats_e garmin_format) +int gt_find_icon_number_from_desc(const QString desc, garmin_formats_e garmin_format) { static int find_flag = 0; icon_mapping_t* i; int def_icon = DEFAULT_ICON_VALUE; int n; - if (!desc) { + if (desc.isNull()) { return def_icon; } @@ -787,12 +787,12 @@ int gt_find_icon_number_from_desc(const char* desc, garmin_formats_e garmin_form * If we were given a numeric icon number as a description * (i.e. 8255), just return that. */ - n = atoi(desc); + n = desc.toInt(); if (n) { return n; } - if (0 == case_ignore_strncmp(desc, "Custom ", 7)) { + if (desc.startsWith("Custom ", Qt::CaseInsensitive)) { int base = 0; if (garmin_format == GDB) { base = 500; @@ -801,13 +801,13 @@ int gt_find_icon_number_from_desc(const char* desc, garmin_formats_e garmin_form base = 7680; } if (base) { - n = atoi(&desc[7]); + n = desc.mid(7).toInt(); return n + base; } } for (i = garmin_smart_icon_table; global_opts.smart_icons && i->icon; i++) { - if (case_ignore_strcmp(desc,i->icon) == 0) { + if (desc.compare(i->icon, Qt::CaseInsensitive) == 0) { switch (garmin_format) { case MAPSOURCE: case GDB: @@ -821,7 +821,7 @@ int gt_find_icon_number_from_desc(const char* desc, garmin_formats_e garmin_form } } for (i = garmin_icon_table; i->icon; i++) { - if (case_ignore_strcmp(desc,i->icon) == 0) { + if (desc.compare(i->icon, Qt::CaseInsensitive) == 0) { switch (garmin_format) { case MAPSOURCE: case GDB: @@ -845,19 +845,17 @@ int gt_find_icon_number_from_desc(const char* desc, garmin_formats_e garmin_form const char* prefixes[] = { "White ", "Red ", "Green ", "Blue ", "Black ", NULL }; - + // Rewrite "Green Square" to "Square, Green". for (prefix = prefixes; *prefix != NULL; prefix++) { - int len = strlen(*prefix); - - if (case_ignore_strncmp(desc, *prefix, len) == 0) { - char buff[64]; - int result; - - snprintf(buff, sizeof(buff), "%s, %s", &desc[len], *prefix); - rtrim(buff); + if (desc.startsWith(*prefix, Qt::CaseInsensitive)) { + QString buff = desc; + buff.replace(*prefix, ""); + buff.append(", "); + buff.append(*prefix); + buff = buff.trimmed(); find_flag = 1; - result = gt_find_icon_number_from_desc(buff, garmin_format); + int result = gt_find_icon_number_from_desc(buff, garmin_format); find_flag = 0; return result; @@ -1039,7 +1037,7 @@ gt_lookup_datum_index(const char* datum_str, const char* module) } gbuint32 -gt_color_value(const int garmin_index) +gt_color_value(const unsigned int garmin_index) { if ((garmin_index >= 0) && (garmin_index < GT_COLORS_CT)) { return gt_colors[garmin_index].rgb; @@ -1088,7 +1086,7 @@ gt_color_index_by_rgb(const int rgb) } const char* -gt_color_name(const int garmin_index) +gt_color_name(const unsigned int garmin_index) { if ((garmin_index >= 0) && (garmin_index < GT_COLORS_CT)) { return gt_colors[garmin_index].name; diff --git a/gpsbabel/garmin_tables.h b/gpsbabel/garmin_tables.h index ba8a86efd..9e06474d0 100644 --- a/gpsbabel/garmin_tables.h +++ b/gpsbabel/garmin_tables.h @@ -37,7 +37,7 @@ typedef struct icon_mapping { typedef enum {MAPSOURCE, PCX, GARMIN_SERIAL, GDB} garmin_formats_e; const char* gt_find_desc_from_icon_number(const int icon, garmin_formats_e garmin_format, int* dynamic); -int gt_find_icon_number_from_desc(const char* desc, garmin_formats_e garmin_format); +int gt_find_icon_number_from_desc(const QString desc, garmin_formats_e garmin_format); extern icon_mapping_t garmin_icon_table[]; @@ -95,10 +95,10 @@ grid_type gt_lookup_grid_type(const char* grid_name, const char* module); const char* gt_get_mps_grid_longname(const grid_type grid, const char* module); int gt_lookup_datum_index(const char* datum_str, const char* module); const char* gt_get_mps_datum_name(const int datum_index); -gbuint32 gt_color_value(const int garmin_index); +gbuint32 gt_color_value(const unsigned int garmin_index); gbuint32 gt_color_value_by_name(const char* name); int gt_color_index_by_name(const char* name); int gt_color_index_by_rgb(const int rgb); -const char* gt_color_name(const int garmin_index); +const char* gt_color_name(const unsigned int garmin_index); #endif diff --git a/gpsbabel/garmin_txt.cc b/gpsbabel/garmin_txt.cc index 12bcd60cb..8c1415351 100644 --- a/gpsbabel/garmin_txt.cc +++ b/gpsbabel/garmin_txt.cc @@ -524,7 +524,7 @@ print_string(const char* fmt, const char* string) } static void -print_string(const char* fmt, const QString string) +print_string(const char* fmt, QString string) { print_string(fmt, string.toUtf8().data()); } @@ -1174,7 +1174,6 @@ parse_waypoint(void) i = gt_find_icon_number_from_desc(str, GDB); GMSD_SET(icon, i); wpt->icon_descr = gt_find_desc_from_icon_number(i, GDB, &dynamic); - wpt->wpt_flags.icon_descr_is_dynamic = dynamic; break; case 12: GMSD_SETSTR(facility, str); diff --git a/gpsbabel/gbfile.cc b/gpsbabel/gbfile.cc index e85d5622e..a021320b5 100644 --- a/gpsbabel/gbfile.cc +++ b/gpsbabel/gbfile.cc @@ -1253,6 +1253,15 @@ gbfputpstr(const char* s, gbfile* file) return (len + 1); } +int +gbfputpstr(const QString s, gbfile* file) +{ + const char *t = s.toUtf8().data(); + int r = gbfputpstr(t, file); + xfree(t); + return r; +} + /* Much more higher level functions */ gbsize_t diff --git a/gpsbabel/gbfile.h b/gpsbabel/gbfile.h index 7b9a05b9c..0aa9ef72f 100644 --- a/gpsbabel/gbfile.h +++ b/gpsbabel/gbfile.h @@ -132,6 +132,7 @@ int gbfputflt(const float f, gbfile* file); // write a float value int gbfputcstr(const char* s, gbfile* file); // write string including '\0' int gbfputcstr(const QString s, gbfile* file); // write string including '\0' int gbfputpstr(const char* s, gbfile* file); // write as pascal string +int gbfputpstr(const QString s, gbfile* file); // write as pascal string gbsize_t gbfcopyfrom(gbfile* file, gbfile* src, gbsize_t count); diff --git a/gpsbabel/gdb.cc b/gpsbabel/gdb.cc index a6de7878a..6a726651e 100644 --- a/gpsbabel/gdb.cc +++ b/gpsbabel/gdb.cc @@ -699,7 +699,6 @@ read_waypoint(gt_waypt_classes_e* waypt_class_out) } res->icon_descr = gt_find_desc_from_icon_number(icon, GDB, &dynamic); - res->wpt_flags.icon_descr_is_dynamic = dynamic; #if GDB_DEBUG DBG(GDB_DBG_WPTe, icon != GDB_DEF_ICON) @@ -1673,10 +1672,10 @@ write_waypoint_cb(const waypoint* refpt) icon = GMSD_GET(icon, -1); if (icon < 0) { - if (wpt->icon_descr) { - icon = gt_find_icon_number_from_desc(wpt->icon_descr, GDB); - } else { + if (wpt->icon_descr.isNull()) { icon = GDB_DEF_ICON; + } else { + icon = gt_find_icon_number_from_desc(wpt->icon_descr, GDB); } } diff --git a/gpsbabel/geo.cc b/gpsbabel/geo.cc index 0d21ea059..09428d12e 100644 --- a/gpsbabel/geo.cc +++ b/gpsbabel/geo.cc @@ -140,8 +140,7 @@ void wpt_link(const char* args, const char** attrv) void wpt_type(const char* args, const char** unused) { - wpt_tmp->wpt_flags.icon_descr_is_dynamic = 1; - wpt_tmp->icon_descr = xstrdup(args); + wpt_tmp->icon_descr = args; } void wpt_coord(const char* args, const char** attrv) diff --git a/gpsbabel/geoniche.cc b/gpsbabel/geoniche.cc index 1e6246d8e..88e347d2d 100644 --- a/gpsbabel/geoniche.cc +++ b/gpsbabel/geoniche.cc @@ -388,7 +388,6 @@ geoniche_read_asc(void) wpt->longitude = lon; wpt->altitude = alt; wpt->icon_descr = category; - wpt->wpt_flags.icon_descr_is_dynamic = 1; if (gid[0]) { wpt->shortname = xstrdup(gid); @@ -458,7 +457,7 @@ static const char* geoniche_icon_map[] = /* MPS */ /* 52 */ "Mystery or puzzle Cache", }; -static const char* +static const QString geoniche_icon_to_descr(const int no) { const char* result = NULL; @@ -547,10 +546,6 @@ geoniche_read_bin(void) GPS_Math_DegMin_To_Deg(londeg, lon, &waypt->longitude); waypt->icon_descr = geoniche_icon_to_descr(icon_nr); - if (waypt->icon_descr != NULL) { - waypt->wpt_flags.icon_descr_is_dynamic = 1; - } - waypt_add(waypt); } } @@ -616,31 +611,31 @@ enscape(char* s) static int wpt2icon(const waypoint* wpt) { - const char* desc = wpt->icon_descr; + QString desc = wpt->icon_descr; - if (!desc) { + if (desc.isNull()) { return 0; - } else if (strstr(desc, "reg")) { + } else if (desc.contains("reg")) { return 43; - } else if (strstr(desc, "trad")) { + } else if (desc.contains("trad")) { return 43; - } else if (strstr(desc, "multi")) { + } else if (desc.contains("multi")) { return 44; - } else if (strstr(desc, "offset")) { + } else if (desc.contains("offset")) { return 44; - } else if (strstr(desc, "virt")) { + } else if (desc.contains("virt")) { return 45; - } else if (strstr(desc, "loca")) { + } else if (desc.contains("loca")) { return 45; - } else if (strstr(desc, "event")) { + } else if (desc.contains("event")) { return 46; - } else if (strstr(desc, "lett")) { + } else if (desc.contains("lett")) { return 47; - } else if (strstr(desc, "hyb")) { + } else if (desc.contains("hyb")) { return 47; - } else if (strstr(desc, "unk")) { + } else if (desc.contains("unk")) { return 48; - } else if (strstr(desc, "cam")) { + } else if (desc.contains("cam")) { return 49; } diff --git a/gpsbabel/gpilots.cc b/gpsbabel/gpilots.cc index 55e04a189..9abf748fb 100644 --- a/gpsbabel/gpilots.cc +++ b/gpsbabel/gpilots.cc @@ -261,7 +261,6 @@ data_read(void) WAYPT_SET(wpt_tmp, depth, fi.f); fi.i = le_read32(&rec->wpt.d108.dist); WAYPT_SET(wpt_tmp, proximity, fi.f); - wpt_tmp->wpt_flags.icon_descr_is_dynamic = 0; wpt_tmp->icon_descr = gt_find_desc_from_icon_number((rec->wpt.d108.smbl[1] << 8) + rec->wpt.d108.smbl[0], PCX, NULL); waypt_add(wpt_tmp); break; diff --git a/gpsbabel/gpsutil.cc b/gpsbabel/gpsutil.cc index 0fae24e9b..283d970dc 100644 --- a/gpsbabel/gpsutil.cc +++ b/gpsbabel/gpsutil.cc @@ -135,7 +135,7 @@ static void gpsutil_disp(const waypoint* wpt) { double lon,lat; - const char* icon_token; + QString icon_token; char* tdesc = xstrdup(wpt->description); icon_token = mag_find_token_from_descr(wpt->icon_descr); @@ -155,7 +155,7 @@ gpsutil_disp(const waypoint* wpt) (wpt->altitude < 0.0)) ? 0 : wpt->altitude, 'm', wpt->description ? tdesc : "", - icon_token); + icon_token.toUtf8().data()); xfree(tdesc); } diff --git a/gpsbabel/gpx.cc b/gpsbabel/gpx.cc index 735d8bf08..3131a498b 100644 --- a/gpsbabel/gpx.cc +++ b/gpsbabel/gpx.cc @@ -1133,8 +1133,7 @@ gpx_end(void* data, const XML_Char* xml_el) case tt_wpt_sym: case tt_rte_rtept_sym: case tt_trk_trkseg_trkpt_sym: - wpt_tmp->icon_descr = xstrdup(cdatastrp); - wpt_tmp->wpt_flags.icon_descr_is_dynamic = 1; + wpt_tmp->icon_descr = cdatastrp; break; case tt_wpt_time: case tt_trk_trkseg_trkpt_time: diff --git a/gpsbabel/gtm.cc b/gpsbabel/gtm.cc index 8a4db6272..6b500eeef 100644 --- a/gpsbabel/gtm.cc +++ b/gpsbabel/gtm.cc @@ -712,14 +712,12 @@ gtm_read(void) } } -int icon_from_descr(const char* descr) +int icon_from_descr(QString descr) { - if (descr) { - int i; - for (i = 0; icon_descr[i]; i++) - if (strcmp(icon_descr[i], descr) == 0) { - return i; - } + for (int i = 0; icon_descr[i]; i++) { + if (descr.compare(icon_descr[i]) == 0) { + return i; + } } return 48; } diff --git a/gpsbabel/gtrnctr.cc b/gpsbabel/gtrnctr.cc index 4da40f2ff..455040337 100644 --- a/gpsbabel/gtrnctr.cc +++ b/gpsbabel/gtrnctr.cc @@ -615,8 +615,7 @@ gtc_wpt_long(const char* args, const char** unused) void gtc_wpt_icon(const char* args, const char** unused) { - wpt_tmp->icon_descr = xstrdup(args); - wpt_tmp->wpt_flags.icon_descr_is_dynamic = 1; + wpt_tmp->icon_descr = args; } void diff --git a/gpsbabel/hiketech.cc b/gpsbabel/hiketech.cc index cdde9a520..bab21cdc8 100644 --- a/gpsbabel/hiketech.cc +++ b/gpsbabel/hiketech.cc @@ -184,8 +184,7 @@ void ht_ident(const char* args, const char** unused) static void ht_sym(const char* args, const char** unused) { - wpt_tmp->icon_descr = xstrdup(args); - wpt_tmp->wpt_flags.icon_descr_is_dynamic = 1; + wpt_tmp->icon_descr = args; } static diff --git a/gpsbabel/humminbird.cc b/gpsbabel/humminbird.cc index 4eaa7f85e..464b46306 100644 --- a/gpsbabel/humminbird.cc +++ b/gpsbabel/humminbird.cc @@ -655,9 +655,9 @@ humminbird_write_waypoint(const waypoint* wpt) hum.icon = 255; // Icon.... - if (wpt->icon_descr) { + if (!wpt->icon_descr.isNull()) { for (i = 0; i < num_icons; i++) { - if (!case_ignore_strcmp(wpt->icon_descr, humminbird_icons[i])) { + if (!wpt->icon_descr.compare(humminbird_icons[i], Qt::CaseInsensitive)) { hum.icon = i; break; } @@ -668,7 +668,7 @@ humminbird_write_waypoint(const waypoint* wpt) char* match; int j; xasprintf(&match, "*%s*", humminbird_icons[i]); - j = case_ignore_str_match(wpt->icon_descr, match); + j = wpt->icon_descr.compare(match, Qt::CaseInsensitive); xfree(match); if (j != 0) { hum.icon = i; diff --git a/gpsbabel/kml.cc b/gpsbabel/kml.cc index fb797453e..72313555e 100644 --- a/gpsbabel/kml.cc +++ b/gpsbabel/kml.cc @@ -344,8 +344,7 @@ void wpt_coord(const char* args, const char** attrv) void wpt_icon(const char* args, const char** unused) { if (wpt_tmp) { - wpt_tmp->icon_descr = xstrdup(args); - wpt_tmp->wpt_flags.icon_descr_is_dynamic = 1; + wpt_tmp->icon_descr = args; } } @@ -1506,7 +1505,7 @@ static void kml_geocache_pr(const waypoint* waypointp) static void kml_waypt_pr(const waypoint* waypointp) { - const char* icon; + QString icon; #if 0 // Experimental if (realtime_positioning) { @@ -1553,11 +1552,11 @@ static void kml_waypt_pr(const waypoint* waypointp) // Icon - but only if it looks like a URL. icon = opt_deficon ? opt_deficon : waypointp->icon_descr; - if (icon && strstr(icon, "://")) { + if (icon.contains("://")) { kml_write_xml(1, "\n"); diff --git a/gpsbabel/lowranceusr.cc b/gpsbabel/lowranceusr.cc index 9df1c3afb..c2e835cb0 100644 --- a/gpsbabel/lowranceusr.cc +++ b/gpsbabel/lowranceusr.cc @@ -268,12 +268,12 @@ lowranceusr_find_desc_from_icon_number(const int icon) } int -lowranceusr_find_icon_number_from_desc(const char* desc) +lowranceusr_find_icon_number_from_desc(QString desc) { const lowranceusr_icon_mapping_t* i; int n; - if (!desc) { + if (desc.isNull()) { return DEF_ICON; } @@ -281,14 +281,14 @@ lowranceusr_find_icon_number_from_desc(const char* desc) * If we were given a numeric icon number as a description * (i.e. 8255), just return that. */ - n = atoi(desc); + n = desc.toInt(); if (n) { return n; } for (i = lowranceusr_icon_value_table; i->icon; i++) { - if (case_ignore_strcmp(desc,i->icon) == 0) { + if (desc.compare(i->icon,Qt::CaseInsensitive) == 0) { return i->value; } } @@ -422,11 +422,10 @@ lowranceusr_parse_waypt(waypoint* wpt_tmp) /* Symbol ID */ wpt_tmp->icon_descr = lowranceusr_find_desc_from_icon_number(gbfgetint32(file_in)); - if (!wpt_tmp->icon_descr[0]) { + if (wpt_tmp->icon_descr.isNull()) { char nbuf[10]; snprintf(nbuf, sizeof(nbuf), "%d", le_read32(buff)); - wpt_tmp->wpt_flags.icon_descr_is_dynamic = 1; - wpt_tmp->icon_descr = xstrdup(nbuf); + wpt_tmp->icon_descr = nbuf; } /* Waypoint Type (USER, TEMPORARY, POINT_OF_INTEREST) */ @@ -769,7 +768,7 @@ lowranceusr_waypt_disp(const waypoint* wpt) gbfputint32(Time, file_out); - if (get_cache_icon(wpt) && wpt->icon_descr && (strcmp(wpt->icon_descr, "Geocache Found") != 0)) { + if (get_cache_icon(wpt) && wpt->icon_descr.compare("Geocache Found") == 0) { SymbolId = lowranceusr_find_icon_number_from_desc(get_cache_icon(wpt)); } else { SymbolId = lowranceusr_find_icon_number_from_desc(wpt->icon_descr); @@ -815,7 +814,7 @@ lowranceusr_write_icon(const waypoint* wpt) { int latmm = lat_deg_to_mm(wpt->latitude); int lonmm = lon_deg_to_mm(wpt->longitude); - int icon = wpt->icon_descr ? + int icon = !wpt->icon_descr.isNull() ? lowranceusr_find_icon_number_from_desc(wpt->icon_descr) : 10003; diff --git a/gpsbabel/magellan.h b/gpsbabel/magellan.h index 582f9c75a..2363c1ef0 100644 --- a/gpsbabel/magellan.h +++ b/gpsbabel/magellan.h @@ -44,8 +44,8 @@ typedef struct icon_mapping { const char* icon; } icon_mapping_t; -const char* mag_find_descr_from_token(const char* token); -const char* mag_find_token_from_descr(const char* icon); +QString mag_find_descr_from_token(const char* token); +QString mag_find_token_from_descr(QString icon); unsigned int mag_checksum(const char* const buf); char* m330_cleanse(char* istring); diff --git a/gpsbabel/magproto.cc b/gpsbabel/magproto.cc index d34fabbce..0b5f55b0d 100644 --- a/gpsbabel/magproto.cc +++ b/gpsbabel/magproto.cc @@ -1157,7 +1157,7 @@ mag_rteparse(char* rtemsg) } } -const char* +QString mag_find_descr_from_token(const char* token) { icon_mapping_t* i = icon_mapping; @@ -1177,8 +1177,8 @@ mag_find_descr_from_token(const char* token) return icon_mapping[0].icon; } -const char* -mag_find_token_from_descr(const char* icon) +QString +mag_find_token_from_descr(QString icon) { icon_mapping_t* i = icon_mapping; @@ -1187,7 +1187,7 @@ mag_find_token_from_descr(const char* icon) } for (i = icon_mapping; i->token; i++) { - if (case_ignore_strcmp(icon, i->icon) == 0) { + if (icon.compare(i->icon, Qt::CaseInsensitive) == 0) { return i->token; } } @@ -1346,7 +1346,7 @@ mag_waypt_pr(const waypoint* waypointp) int lon_deg, lat_deg; char obuf[200]; char ofmtdesc[200]; - const char* icon_token=NULL; + QString icon_token; char* owpt; char* odesc; char* isrc = NULL; @@ -1408,7 +1408,7 @@ mag_waypt_pr(const waypoint* waypointp) wpt_len, owpt, odesc, - icon_token); + icon_token.toUtf8().data()); mag_writemsg(obuf); xfree(owpt); xfree(odesc); @@ -1505,7 +1505,7 @@ mag_route_trl(const route_head* rte) char obuff[256]; char buff1[64], buff2[64]; char* pbuff, *owpt; - const char* icon_token; + QString icon_token; int i, numlines, thisline; /* count waypoints for this route */ @@ -1540,7 +1540,7 @@ mag_route_trl(const route_head* rte) } owpt = mag_cleanse(owpt); - sprintf(pbuff, "%s,%s", owpt, icon_token); + sprintf(pbuff, "%s,%s", owpt, icon_token.toUtf8().data()); xfree(owpt); diff --git a/gpsbabel/mapsend.cc b/gpsbabel/mapsend.cc index 480eda80a..6bfb41fb7 100644 --- a/gpsbabel/mapsend.cc +++ b/gpsbabel/mapsend.cc @@ -270,10 +270,9 @@ mapsend_read(void) static void mapsend_waypt_pr(const waypoint* waypointp) { - unsigned char c; + unsigned int c = 0; double falt; static int cnt = 0; - const char* iconp = NULL; const char* sn = global_opts.synthesize_shortnames ? mkshort_from_wpt(mkshort_handle, waypointp) : waypointp->shortname; @@ -316,23 +315,25 @@ mapsend_waypt_pr(const waypoint* waypointp) /* #, icon, status */ gbfputint32(++cnt, mapsend_file_out); + - if (waypointp->icon_descr) { + QString iconp; + if (!waypointp->icon_descr.isNull()) { iconp = mag_find_token_from_descr(waypointp->icon_descr); - if (1 == strlen(iconp)) { - c = iconp[0] - 'a'; + if (1 == iconp.size()) { + c = iconp[0].toAscii() - 'a'; } else { - c = iconp[1] - 'a' + 26; + c = iconp[1].toAscii() - 'a' + 26; } } else { c = 0; } if (get_cache_icon(waypointp)) { iconp = mag_find_token_from_descr(get_cache_icon(waypointp)); - if (1 == strlen(iconp)) { - c = iconp[0] - 'a'; + if (1 == iconp.size()) { + c = iconp[0].toAscii() - 'a'; } else { - c = iconp[1] - 'a' + 26; + c = iconp[1].toAscii() - 'a' + 26; } } @@ -381,7 +382,7 @@ static void mapsend_route_disp(const waypoint* waypointp) { unsigned char c; - const char* iconp; + QString iconp; route_wp_count++; @@ -396,12 +397,12 @@ mapsend_route_disp(const waypoint* waypointp) gbfputdbl(waypointp->longitude, mapsend_file_out); gbfputdbl(-waypointp->latitude, mapsend_file_out); - if (waypointp->icon_descr) { + if (!waypointp->icon_descr.isNull()) { iconp = mag_find_token_from_descr(waypointp->icon_descr); - if (1 == strlen(iconp)) { - c = iconp[0] - 'a'; + if (1 == iconp.size()) { + c = iconp[0].toAscii() - 'a'; } else { - c = iconp[1] - 'a' + 26; + c = iconp[1].toAscii() - 'a' + 26; } } else { c = 0; diff --git a/gpsbabel/mapsource.cc b/gpsbabel/mapsource.cc index ecea85cad..690bf342d 100644 --- a/gpsbabel/mapsource.cc +++ b/gpsbabel/mapsource.cc @@ -592,7 +592,6 @@ mps_waypoint_r(gbfile* mps_file, int mps_ver, waypoint** wpt, unsigned int* mpsc /* might need to change this to handle version dependent icon handling */ thisWaypoint->icon_descr = gt_find_desc_from_icon_number(icon, MAPSOURCE, &dynamic); - thisWaypoint->wpt_flags.icon_descr_is_dynamic = dynamic; /* The following Now done elsewhere since it can be useful to read in and perhaps not add to the list */ @@ -611,7 +610,7 @@ mps_waypoint_w(gbfile* mps_file, int mps_ver, const waypoint* wpt, const int isR int reclen; int lat, lon; int icon; - char* src = ""; /* default to empty string */ + const char* src = ""; /* default to empty string */ char* ident; char* ascii_description; char zbuf[25]; @@ -644,8 +643,7 @@ mps_waypoint_w(gbfile* mps_file, int mps_ver, const waypoint* wpt, const int isR /* might need to change this to handle version dependent icon handling */ icon = gt_find_icon_number_from_desc(wpt->icon_descr, MAPSOURCE); - - if (get_cache_icon(wpt) /* && wpt->icon_descr && (strcmp(wpt->icon_descr, "Geocache Found") != 0)*/) { + if (get_cache_icon(wpt)) { icon = gt_find_icon_number_from_desc(get_cache_icon(wpt), MAPSOURCE); } @@ -1119,7 +1117,7 @@ mps_routehdr_w(gbfile* mps_file, int mps_ver, const route_head* rte) char* rname; char hdr[20]; char zbuf[20]; - char* src = ""; + const char* src = ""; char* ident; waypoint* testwpt; @@ -1283,7 +1281,7 @@ mps_routedatapoint_w(gbfile* mps_file, int mps_ver, const waypoint* rtewpt) int lon; char zbuf[20]; char ffbuf[20]; - char* src = ""; + const char* src = ""; char* ident; int reclen; diff --git a/gpsbabel/mmo.cc b/gpsbabel/mmo.cc index b86e5c640..d46ba9ace 100644 --- a/gpsbabel/mmo.cc +++ b/gpsbabel/mmo.cc @@ -567,9 +567,8 @@ mmo_read_CObjWaypoint(mmo_data_t* data) snprintf(key, sizeof(key), "%d", i); if (avltree_find(icons, key, (const void**)&name)) { - wpt->icon_descr = xstrdup(name); - wpt->wpt_flags.icon_descr_is_dynamic = 1; - DBG((sobj, "icon = \"%s\"\n", wpt->icon_descr)); + wpt->icon_descr = name; + DBG((sobj, "icon = \"%s\"\n", wpt->icon_descr.toUtf8().data())); } #ifdef MMO_DBG else { @@ -1020,9 +1019,8 @@ mmo_finalize_rtept_cb(const waypoint* wptref) wpt->proximity = wpt2->proximity; wpt->wpt_flags.proximity = wpt2->wpt_flags.proximity; - if (wpt2->icon_descr) { - wpt->icon_descr = xstrdup(wpt2->icon_descr); - wpt->wpt_flags.icon_descr_is_dynamic = 1; + if (!wpt2->icon_descr.isNull()) { + wpt->icon_descr = wpt2->icon_descr; } } } @@ -1347,11 +1345,11 @@ mmo_write_wpt_cb(const waypoint* wpt) gbfputflt(0, fout); } - if (wpt->icon_descr) { + if (!wpt->icon_descr.isNull()) { int i = 0; while (mmo_icon_value_table[i].icon) { - if (case_ignore_strcmp(wpt->icon_descr, mmo_icon_value_table[i].icon) == 0) { + if (wpt->icon_descr.compare(mmo_icon_value_table[i].icon, Qt::CaseInsensitive) == 0) { icon = mmo_icon_value_table[i].value; break; } diff --git a/gpsbabel/navilink.cc b/gpsbabel/navilink.cc index 9f80ecf72..d3e175687 100644 --- a/gpsbabel/navilink.cc +++ b/gpsbabel/navilink.cc @@ -174,12 +174,12 @@ static void (*write_route_point)(const waypoint* waypt) = NULL; static void (*write_route_end)(const route_head* track) = NULL; static int -find_icon_from_descr(const char* descr) +find_icon_from_descr(QString descr) { unsigned int i; - for (i = 0; descr && i < sizeof(icon_table) / sizeof(const char*); i++) { - if (strcmp(descr, icon_table[i]) == 0) { + for (i = 0; i < sizeof(icon_table) / sizeof(const char*); i++) { + if (0 == descr.compare(icon_table[i])) { return i; } } diff --git a/gpsbabel/osm.cc b/gpsbabel/osm.cc index 0ed51f384..345dd01d1 100644 --- a/gpsbabel/osm.cc +++ b/gpsbabel/osm.cc @@ -461,7 +461,7 @@ osm_feature_ikey(const char* key) } -static char* +static QString osm_feature_symbol(const int ikey, const char* value) { char* result; @@ -565,7 +565,6 @@ osm_node_tag(const char* args, const char** attrv) wpt->shortname = xstrdup(str); } else if ((ikey = osm_feature_ikey(key)) >= 0) { wpt->icon_descr = osm_feature_symbol(ikey, value); - wpt->wpt_flags.icon_descr_is_dynamic = 1; } else if (strcmp(key, "note") == 0) { if (wpt->notes) { char* tmp; @@ -854,7 +853,7 @@ osm_waypt_disp(const waypoint* wpt) osm_write_tag("name", wpt->shortname); osm_write_tag("note", (wpt->notes) ? wpt->notes : wpt->description); - if (wpt->icon_descr) { + if (!wpt->icon_descr.isNull()) { osm_disp_feature(wpt); } diff --git a/gpsbabel/ozi.cc b/gpsbabel/ozi.cc index 90632a7ce..eddda268c 100644 --- a/gpsbabel/ozi.cc +++ b/gpsbabel/ozi.cc @@ -537,8 +537,7 @@ ozi_parse_waypt(int field, char *str, waypoint * wpt_tmp, ozi_fsdata *fsdata) other types, but it at least maintains fidelity for an ozi->ozi operation. */ if (str && isdigit(str[0])) { - wpt_tmp->icon_descr = xstrdup(str); - wpt_tmp->wpt_flags.icon_descr_is_dynamic = 1; + wpt_tmp->icon_descr = str; } break; case 6: @@ -921,8 +920,8 @@ ozi_waypt_pr(const waypoint * wpt) index++; - if (wpt->icon_descr && isdigit(wpt->icon_descr[0])) { - icon = atoi(wpt->icon_descr); + if (wpt->icon_descr.toInt()) { + icon = wpt->icon_descr.toInt(); } gbfprintf(file_out, diff --git a/gpsbabel/pathaway.cc b/gpsbabel/pathaway.cc index 8ded97995..f982fa18e 100644 --- a/gpsbabel/pathaway.cc +++ b/gpsbabel/pathaway.cc @@ -472,9 +472,8 @@ int ppdb_read_wpt(route_head *head, int isRoute) break; case 6: /* icon */ if (*str != '\0') { - wpt_tmp->icon_descr = xstrdup(str); + wpt_tmp->icon_descr = str; } - wpt_tmp->wpt_flags.icon_descr_is_dynamic = 1; break; case 7: /* notes */ if (*str != '\0') { @@ -711,7 +710,7 @@ static void ppdb_write_wpt(const waypoint *wpt) buff = ppdb_strcat(buff, ",", NULL, &len); /* 6 icon */ - tmp = str_pool_getcpy(wpt->icon_descr, opt_deficon); /* point icon or deficon from options */ + tmp = str_pool_getcpy(wpt->icon_descr.toUtf8().data(), opt_deficon); /* point icon or deficon from options */ buff = ppdb_strcat(buff, tmp, NULL, &len); buff = ppdb_strcat(buff, ",", NULL, &len); /* 7 description */ diff --git a/gpsbabel/psitrex.cc b/gpsbabel/psitrex.cc index 9a6b64b4d..3dd5ac2eb 100644 --- a/gpsbabel/psitrex.cc +++ b/gpsbabel/psitrex.cc @@ -362,7 +362,7 @@ psit_waypoint_w(gbfile *psit_file, const waypoint *wpt) gbfprintf(psit_file, " %-6s, ", ident); icon = gt_find_icon_number_from_desc(wpt->icon_descr, PCX); - if (get_cache_icon(wpt) && wpt->icon_descr && (strcmp(wpt->icon_descr, "Geocache Found") != 0)) { + if (get_cache_icon(wpt) && wpt->icon_descr.compare("Geocache Found") != 0) { icon = gt_find_icon_number_from_desc(get_cache_icon(wpt), PCX); } diff --git a/gpsbabel/raymarine.cc b/gpsbabel/raymarine.cc index 4e03610d2..403adf5a4 100644 --- a/gpsbabel/raymarine.cc +++ b/gpsbabel/raymarine.cc @@ -140,19 +140,19 @@ static raymarine_symbol_mapping_t raymarine_symbols[] = { #define RAYMARINE_STD_SYMBOL 3 static int -find_symbol_num(const char *descr) +find_symbol_num(const QString descr) { - if ((descr != NULL) && (*descr)) { + if (!descr.isNull()) { raymarine_symbol_mapping_t *a; a = &raymarine_symbols[0]; for (unsigned int i = 0; i < RAYMARINE_SYMBOL_CT; i++, a++) { - if (case_ignore_strcmp(descr, a->name) == 0) { + if (descr.compare(a->name, Qt::CaseInsensitive) == 0) { return i; } - if (a->mps_name && (case_ignore_strcmp(descr, a->mps_name) == 0)) { + if (a->mps_name && (descr.compare(a->mps_name, Qt::CaseInsensitive) == 0)) { return i; } } diff --git a/gpsbabel/tiger.cc b/gpsbabel/tiger.cc index 3560de17a..7ceb90d32 100644 --- a/gpsbabel/tiger.cc +++ b/gpsbabel/tiger.cc @@ -179,13 +179,13 @@ data_read(void) static void tiger_disp(const waypoint *wpt) { - const char *pin; + QString pin; double lat = wpt->latitude; double lon = wpt->longitude; if (iconismarker) { - pin = wpt->icon_descr ? wpt->icon_descr : ""; - } else if (wpt->icon_descr && strstr(wpt->icon_descr, "-unfound")) { + pin = wpt->icon_descr; + } else if (wpt->icon_descr.contains("-unfound")) { pin = unfoundmarker; } else if (wpt->creation_time > current_time() - 3600 * 24 * thresh_days) { pin = newmarker; @@ -208,7 +208,7 @@ tiger_disp(const waypoint *wpt) } } - gbfprintf(file_out, "%f,%f:%s", lon, lat, pin); + gbfprintf(file_out, "%f,%f:%s", lon, lat, pin.toUtf8().data()); if (!nolabels) { char *temp = NULL; char *desc = csv_stringclean(wpt->description, ":"); diff --git a/gpsbabel/unicsv.cc b/gpsbabel/unicsv.cc index 3d5dc16b4..d4d3a1ac7 100644 --- a/gpsbabel/unicsv.cc +++ b/gpsbabel/unicsv.cc @@ -940,8 +940,7 @@ unicsv_parse_one_line(char *ibuf) break; case fld_symbol: - wpt->icon_descr = xstrdup(s); - wpt->wpt_flags.icon_descr_is_dynamic = 1; + wpt->icon_descr = s; break; case fld_iso_time: @@ -1305,6 +1304,14 @@ unicsv_print_str(const char *str) } } +static void +unicsv_print_str(const QString s) +{ + char *t = xstrdup(s.toUtf8().data()); + unicsv_print_str(t); + xfree(t); +} + #ifdef UNICSV_GC_READY static void unicsv_print_data_time(const time_t atime) @@ -1345,7 +1352,7 @@ unicsv_waypt_enum_cb(const waypoint *wpt) if (wpt->altitude != unknown_alt) { gb_setbit(&unicsv_outp_flags, fld_altitude); } - if (wpt->icon_descr && *wpt->icon_descr) { + if (!wpt->icon_descr.isNull()) { gb_setbit(&unicsv_outp_flags, fld_symbol); } if (wpt->description && *wpt->description && (strcmp(shortname, wpt->description) != 0)) { @@ -1603,7 +1610,7 @@ unicsv_waypt_disp_cb(const waypoint *wpt) unicsv_print_str(wpt->notes); } if FIELD_USED(fld_symbol) { - unicsv_print_str((wpt->icon_descr != NULL) ? wpt->icon_descr : "Waypoint"); + unicsv_print_str(wpt->icon_descr.isNull() ? "Waypoint" : wpt->icon_descr); } if FIELD_USED(fld_depth) { if WAYPT_HAS(wpt, depth) { diff --git a/gpsbabel/waypt.cc b/gpsbabel/waypt.cc index 9393f3f1b..f02d2e9de 100644 --- a/gpsbabel/waypt.cc +++ b/gpsbabel/waypt.cc @@ -76,9 +76,8 @@ waypt_dupe(const waypoint *wpt) (url_next->url) ? xstrdup(url_next->url) : NULL, (url_next->url_link_text) ? xstrdup(url_next->url_link_text) : NULL); } - if (wpt->icon_descr && wpt->wpt_flags.icon_descr_is_dynamic) { - tmp->icon_descr = xstrdup(wpt->icon_descr); - } + + tmp->icon_descr = wpt->icon_descr; if (wpt->gc_data != &empty_gc_data) { geocache_data *gc_data = (geocache_data*) xmalloc(sizeof(*gc_data)); @@ -422,9 +421,6 @@ waypt_free(waypoint *wpt) xfree(tonuke); } } - if (wpt->icon_descr && wpt->wpt_flags.icon_descr_is_dynamic) { - xfree((char *)(void *)wpt->icon_descr); - } if (wpt->gc_data != &empty_gc_data) { geocache_data *gc_data = (geocache_data *)wpt->gc_data; diff --git a/gpsbabel/wfff_xml.cc b/gpsbabel/wfff_xml.cc index 1379f0e6c..dca8454b1 100644 --- a/gpsbabel/wfff_xml.cc +++ b/gpsbabel/wfff_xml.cc @@ -241,18 +241,17 @@ void wfff_e(const char *args, const char **unused) wpt_tmp->altitude = unknown_alt; wpt_tmp->fix = fix_unknown; - wpt_tmp->wpt_flags.icon_descr_is_dynamic = 1; if (case_ignore_strncmp(ap_wep,"On",2)==0) { if (case_ignore_strncmp(ap_type,"AP",2)==0) { - wpt_tmp->icon_descr = xstrdup(aicicon); /* Infra Closed */ + wpt_tmp->icon_descr = aicicon; /* Infra Closed */ } else { - wpt_tmp->icon_descr = xstrdup(ahcicon); /* AdHoc Closed */ + wpt_tmp->icon_descr = ahcicon; /* AdHoc Closed */ } } else { if (case_ignore_strncmp(ap_type,"AP",2)==0) { - wpt_tmp->icon_descr = xstrdup(aioicon); /* Infra Open */ + wpt_tmp->icon_descr = aioicon; /* Infra Open */ } else { - wpt_tmp->icon_descr = xstrdup(ahoicon); /* AdHoc Open */ + wpt_tmp->icon_descr = ahoicon; /* AdHoc Open */ } } diff --git a/gpsbabel/xol.cc b/gpsbabel/xol.cc index 874c803ce..0f258f39a 100644 --- a/gpsbabel/xol.cc +++ b/gpsbabel/xol.cc @@ -116,8 +116,7 @@ xol_shape(const char *args, const char **attrv) } } else if (strcmp(avp[0], "icon") == 0) { if (wpt) { - wpt->icon_descr = xstrdup(avp[1]); - wpt->wpt_flags.icon_descr_is_dynamic = 1; + wpt->icon_descr = avp[1]; } } @@ -269,7 +268,7 @@ xol_waypt_disp_cb(const waypoint *wpt) gbfprintf(fout, "%*snotes); - xol_write_string("icon", wpt->icon_descr); + xol_write_string("icon", wpt->icon_descr.toUtf8().data()); if (wpt->creation_time) { xol_write_time(wpt); } -- 2.30.2